using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using SharpMud.Net.Telnet.Session;
using SharpMud.Net;
using SharpMud.MudLib.Common.Entities.Players.Session.States;

namespace SharpMud.MudLib.Common.Entities.Players.Session
{
    /// <summary>
    /// Encapsulates the functionality that ties all of that complicated pre-written telnet
    /// code to the mudlib's player infrastructure
    /// </summary>
    public class TelnetPlayerSession : SharpMud.Net.Telnet.Session.TelnetSessionBase, IHasSessionState<TelnetPlayerSession>
    {
        #region Private Variables
        private SessionStateStack<TelnetPlayerSession> _RootSessionStateStack;
        #endregion

        #region Constructors
        public TelnetPlayerSession()
        {
            _RootSessionStateStack = new SessionStateStack<TelnetPlayerSession>(@"\");
        }
        #endregion

        #region (Optional) Overrides
        protected override void _Initialize()
        {
            base._Initialize();
            _RootSessionStateStack.Push(HostMud.PlayerManager.GetStartingTelnetSessionState(this.Connection));
        }
        protected override void _Pulse()
        {
            base._Pulse();
            SessionState.Pulse();
        }
        #endregion

        #region Public Properties
        public IBaseMudLibRoot HostMud
        {
            get
            {
                return (base.Host.Host as IBaseMudLibRoot);
            }
        }
        #endregion

        #region IHasSessionState<TelnetPlayerSession> Members

        public ISessionStateStack<TelnetPlayerSession> SessionState
        {
            get { return _RootSessionStateStack; }
        }

        #endregion

        #region IHasSessionState Members

        ISessionStateStack IHasSessionState.SessionState
        {
            get { return _RootSessionStateStack; }
        }

        #endregion
    }
}
